﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel;

namespace DataPermissionStudy
{
    class Program
    {
        static void Main(string[] args)
        {
        }
    }

    class QueryResult { }

    class UserCase { }

    class DynamicQuery { }

    class QueryService
    {
        public QueryResult Query(UserCase userCase, DynamicQuery query)
        {
            // 根据 userCase 决定是否或如何动态的追加数据权限。
            return null;
        }

        public QueryResult QueryA(DynamicQuery query)
        {
            return null;
        }

        public QueryResult QueryB(DynamicQuery query)
        {
            return null;
        }
    }

    class SessionInfo
    {
        public Guid UserId { get; set; }

        public Guid DepartmentId { get; set; }
    }

    interface IDataPermissionProvider
    {
        string CreateSQL(SessionInfo sessionInfo, Dictionary<string, object> args);
    }

    [DisplayName("我的")]
    class MySelfDataPermissionProvider : IDataPermissionProvider
    {
        public string CreateSQL(SessionInfo sessionInfo, Dictionary<string, object> args)
        {
            return String.Format("( CreateUserId = '{0}' )", sessionInfo.UserId);
        }
    }

    [DisplayName("指定部门")]
    class DepartmentDataPermissionProvider : IDataPermissionProvider
    {
        public string CreateSQL(SessionInfo sessionInfo, Dictionary<string, object> args)
        {
            return String.Format("( DepartmentId = '{0}' )", args["DepartmentId"]);
        }
    }
}
